using HKB.Common;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class TemProjectBll
	{
		private Conn conn = null;
		public TemProjectBll()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public TemProjectBll(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable GetProjects()
		{
			return this.conn.GetDataTable("Select * From [HL_TemplateProject] Order By TemplateProjectID Desc");
		}
		public DataTable GetProjectByName(string TemplateProjectName)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@TemplateProjectName", DbType.String, TemplateProjectName);
			return this.conn.GetDataTable("Select * From [HL_TemplateProject] Where TemplateProjectName=@TemplateProjectName", new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public string GetProjectNameByID(int ID)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@TemplateProjectID", DbType.Int32, ID);
			return (string)this.conn.GetScalar("Select TemplateProjectName From HL_TemplateProject Where ([TemplateProjectID] = @TemplateProjectID)", new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetProjectByID(int ID)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@TemplateProjectID", DbType.Int32, ID);
			return this.conn.GetDataTable("Select * From HL_TemplateProject Where ([TemplateProjectID] = @TemplateProjectID)", new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetDefaultProject()
		{
			return this.conn.GetDataTable("Select * From HL_TemplateProject Where ([IsDefault] = 1)");
		}
		public string GetDefaultProjectName()
		{
			return (string)this.conn.GetScalar("Select TemplateProjectName From HL_TemplateProject Where ([IsDefault] = 1)", new IDbDataParameter[0]);
		}
		public string GetSkinDir()
		{
			return (string)this.conn.GetScalar("Select SkinDir From HL_TemplateProject Where ([IsDefault] = 1)", new IDbDataParameter[0]);
		}
		public bool AddProject(string TemplateProjectName, string Intro, string Content, int IsDefault, string SkinDir)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@TemplateProjectName", DbType.String, TemplateProjectName),
				this.conn.CreateParameter("@Intro", DbType.String, Intro),
				this.conn.CreateParameter("@Content", DbType.String, Content),
				this.conn.CreateParameter("@IsDefault", DbType.Int32, IsDefault),
				this.conn.CreateParameter("@SkinDir", DbType.String, SkinDir)
			};
			return this.conn.Execute("Insert Into [HL_TemplateProject](TemplateProjectName,Intro,Content,IsDefault,SkinDir) Values(@TemplateProjectName,@Intro,@Content,@IsDefault,@SkinDir)", parameters) >= 1;
		}
		public bool BakProject(string TemplateProjectName, int pid, string SkinDir)
		{
			DataTable projectByID = this.GetProjectByID(pid);
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@TemplateProjectName", DbType.String, TemplateProjectName),
				this.conn.CreateParameter("@Intro", DbType.String, projectByID.Rows[0]["Intro"].ToString()),
				this.conn.CreateParameter("@Content", DbType.String, projectByID.Rows[0]["Content"].ToString()),
				this.conn.CreateParameter("@IsDefault", DbType.Boolean, false),
				this.conn.CreateParameter("@SkinDir", DbType.String, SkinDir)
			};
			return this.conn.Execute("Insert Into [HL_TemplateProject](TemplateProjectName,Intro,Content,IsDefault,SkinDir) Values(@TemplateProjectName,@Intro,@Content,@IsDefault,@SkinDir)", parameters) >= 1;
		}
		public bool DeleteProject(int ID)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@TemplateProjectID", DbType.Int32, ID);
			return this.conn.Execute("Delete From [HL_TemplateProject] Where TemplateProjectID=@TemplateProjectID", new IDbDataParameter[]
			{
				dbDataParameter
			}) == 1;
		}
		public bool SetDefault(int ID)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@TemplateProjectID", DbType.Int32, ID);
			return this.conn.Execute("Update [HL_TemplateProject] Set IsDefault=0;Update [HL_TemplateProject] Set IsDefault=1 Where TemplateProjectID=@TemplateProjectID", new IDbDataParameter[]
			{
				dbDataParameter
			}) >= 1;
		}
	}
}
